package com.system.controller;

import com.system.service.UpFileQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;

@Controller
@RequestMapping("excel")
public class UpFileQuestion {

    @Autowired
    UpFileQuestionService upFileQuestionService;

    /**
     * 上传文件批量导入试题
     *
     */
    @RequestMapping(value = "/InputExcel.do")
    @ResponseBody
    public String InputExcel(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception {
        String flag = "up";// 上传标志
        if (!file.isEmpty()) {
            try {
                String originalFilename = file.getOriginalFilename();// 原文件名字
                InputStream is = file.getInputStream();// 获取输入流
                flag = upFileQuestionService.InputExcel(is, originalFilename);
            } catch (Exception e) {
                flag = "false";// 上传出错
                e.printStackTrace();
            }
        }
        return flag;
    }




}
